/**
 * 表示站点的类
 */
Subwaymap.Station = org.gridsofts.util.Class.define({
    name: "Subwaymap.Station",

    /**
     * 构造函数
     */
    construct: function (container, line, station, group) {
        if (arguments.length == 0 || typeof (arguments[0]) != "object") {
            throw new Error("Object construct parameter is empty, unable to initialize instance of Station.");
        }

        this.container = container;
        this.line = line;
        this.station = station;
        this.group = group;

        // 站点图标半径
        this.radius = this.station.zoomStop ? 25 : 16;
        // 站点图标笔触
        this.thickness = this.radius / 3;
        // 首选颜色
        this.color = "#" + (line?.routeColor && line?.routeColor.length > 0 ?
            line.routeColor : 0x0);

        this.fillColor = "#fff";

        this.repaint();
    },

    /**
     * 方法
     */
    methods: {
        repaint: function () {
            if (!this.station.publishedStop)
                this.actualDrawStation();
        },
        /** 
         * 调用绘图API，在画布上绘制图元
         */
        actualDrawStation: function () {
            var routeMapStopID = this.station.routeMapStopID;
            var subStation = this.station;
            var line = this.line;
            var sprite;

            sprite = new Kinetic.Circle({
                x: this.station.stopX,
                y: this.station.stopY,
                name: routeMapStopID,
                radius: this.radius,
                fill: this.fillColor,
                stroke: this.color,
                strokeWidth: this.thickness,
                tooltip: 'test-test-test'
            });

            // 创建一个文本标签
            var label = new Kinetic.Label({
                x: this.station.stopX + 20,
                y: this.station.stopY,
                opacity: 0 // 初始设为不可见
            });

            // 创建文本对象
            var text = new Kinetic.Text({
                text: '鼠标悬停显示文本',
                fill: 'black',
                fontVariant: 'small-caps',
                align: 'center',
                fontSize: 28,
                fontFamily: 'Arial',
                fill: "#252e3c"
            });

            // 将文本添加到标签
            label.add(text);

            this.group.add(sprite);
            this.group.add(label);

            // 为矩形添加鼠标悬停事件
            sprite.on('mouseover', function () {
                label.setY(sprite.getY() - 50); // 设置文本的位置
                label.setOpacity(0.7); // 设置文本的不透明度
                var stage = subwayMap.stage;
                stage.draw();
            });

            // 为矩形添加鼠标移出事件
            sprite.on('mouseout', function () {
                label.setOpacity(0); // 设置文本的不透明度为0，即不显示
                var stage = subwayMap.stage;
                stage.draw();
            });

            this.group.addEventListener("click", function () {
                setStationPanel(line, subStation);
                return false;
            });

            this.container.add(this.group);
        }

    }
});